/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import analex.FrameManager;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;

/**
 *
 * @author Pedrom
 */
public class frame_CodigoFonte extends javax.swing.JFrame {

    FrameManager app;

    /**
     * Creates new form frame_CodigoFonte
     */
    public frame_CodigoFonte(FrameManager app) {
        initComponents();
        TextLineNumber LineNum = new TextLineNumber(ta_CFonte);
        this.jScrollPane1.setRowHeaderView(LineNum);
        TextLineNumber LineNum2 = new TextLineNumber(ta_tokens);
        this.jScrollPane2.setRowHeaderView(LineNum2);
        TextLineNumber LineNum3 = new TextLineNumber(ta_erros);
        this.jScrollPane3.setRowHeaderView(LineNum3);
        ta_tokens.setEditable(false);
        ta_erros.setEditable(false);
        ta_CFonte.setLineWrap(true);
        ta_CFonte.setWrapStyleWord(true);
        this.app = app;


    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenu2 = new javax.swing.JMenu();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        ta_CFonte = new javax.swing.JTextArea();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        ta_tokens = new javax.swing.JTextArea();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        ta_erros = new javax.swing.JTextArea();
        jMenuBar1 = new javax.swing.JMenuBar();
        mn_analex = new javax.swing.JMenu();
        bt_analex = new javax.swing.JMenuItem();

        jMenu2.setText("jMenu2");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Código-Fonte:");

        ta_CFonte.setColumns(20);
        ta_CFonte.setRows(5);
        jScrollPane1.setViewportView(ta_CFonte);

        jLabel2.setText("Tokens:");

        ta_tokens.setColumns(20);
        ta_tokens.setRows(5);
        jScrollPane2.setViewportView(ta_tokens);

        jLabel3.setText("Erros:");

        ta_erros.setColumns(20);
        ta_erros.setRows(5);
        jScrollPane3.setViewportView(ta_erros);

        mn_analex.setText("Analisar");

        bt_analex.setText("Análise Léxica");
        bt_analex.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_analexActionPerformed(evt);
            }
        });
        mn_analex.add(bt_analex);

        jMenuBar1.add(mn_analex);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 390, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 405, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 349, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE)
                    .addComponent(jScrollPane2))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bt_analexActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_analexActionPerformed
        if (this.ta_CFonte.getText().trim().isEmpty()) {
            JOptionPane.showMessageDialog(null, "Preencha com algum código!");
        } else {
            app.analex(this.ta_CFonte.getText());
        }
    }//GEN-LAST:event_bt_analexActionPerformed

    public void atualizaToken(String token) {
        this.ta_tokens.setText("");
        this.ta_tokens.append(token);
    }

    public void atualizaErro(String erro) {
        this.ta_erros.setText("");
        this.ta_erros.append(erro);
    }
    /**
     * @param args the command line arguments
     *
     * public static void main(String args[]) { /* Set the Nimbus look and feel
     * //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code
     * (optional) ">
     * /* If Nimbus (introduced in Java SE 6) is not available, stay with the
     * default look and feel. For details see
     * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html      *
     * try { for (javax.swing.UIManager.LookAndFeelInfo info :
     * javax.swing.UIManager.getInstalledLookAndFeels()) { if
     * ("Nimbus".equals(info.getName())) {
     * javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } }
     * catch (ClassNotFoundException ex) {
     * java.util.logging.Logger.getLogger(frame_CodigoFonte.class.getName()).log(java.util.logging.Level.SEVERE,
     * null, ex); } catch (InstantiationException ex) {
     * java.util.logging.Logger.getLogger(frame_CodigoFonte.class.getName()).log(java.util.logging.Level.SEVERE,
     * null, ex); } catch (IllegalAccessException ex) {
     * java.util.logging.Logger.getLogger(frame_CodigoFonte.class.getName()).log(java.util.logging.Level.SEVERE,
     * null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) {
     * java.util.logging.Logger.getLogger(frame_CodigoFonte.class.getName()).log(java.util.logging.Level.SEVERE,
     * null, ex); } //</editor-fold>
     *
        /* Create and display the form java.awt.EventQueue.invokeLater(new
     * Runnable() { public void run() { new
     * frame_CodigoFonte().setVisible(true); } }); }
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem bt_analex;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JMenu mn_analex;
    private javax.swing.JTextArea ta_CFonte;
    private javax.swing.JTextArea ta_erros;
    private javax.swing.JTextArea ta_tokens;
    // End of variables declaration//GEN-END:variables
}
